Completed
Branch master (d2f96a)
by Rafael S.
02:27
created

collapse.js ➔ hideAllButCurrent   A

Complexity

Conditions 5

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 18
rs 9.3333
c 0
b 0
f 0
cc 5
1
function hideAllButCurrent(){
2
    //by default all submenut items are hidden
3
    //but we need to rehide them for search
4
    document.querySelectorAll("nav > ul > li > ul li").forEach(function(parent) {
5
        parent.style.display = "none";
6
    });
7
    
8
    //only current page (if it exists) should be opened
9
    var file = window.location.pathname.split("/").pop().replace(/\.html/, '');
10
    document.querySelectorAll("nav > ul > li > a").forEach(function(parent) {
11
        var href = parent.attributes.href.value.replace(/\.html/, '');
12
        if (file === href) {
13
            parent.parentNode.querySelectorAll("ul li").forEach(function(elem) {
14
                elem.style.display = "block";
15
            });
16
        }
17
    });
18
}
19
20
hideAllButCurrent();